package app.calculator;

public class Fomular {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Fomular fomular = new Fomular();
		// Scanner scan = new Scanner(System.in);
		float priceTag = 3840000;
		double firstPercent = 10;
		double eachMonthPercent = 2.6;
		int months = 6;
		int type = 2;
		// System.out.println("A = ");
		// priceTag = scan.nextFloat();
		//
		// System.out.println("Initial percent = ");
		// firstPercent = scan.nextFloat();
		//
		// System.out.println("Percent per month = ");
		// eachMonthPercent = scan.nextFloat();
		//
		// System.out.println("Months = ");
		// months = scan.nextInt();

		String[] str = fomular.export(priceTag, firstPercent, eachMonthPercent,
				months, type);

		for (String s : str) {
			System.out.println(s);
		}
	}

	public String[] export(float priceTag, double firstPercent,
			double eachMonthPercent, int months, int type) {

		float C = 0;
		float B = 0;
		float Z = 0;
		float D = 0; // prio-pay
		
		if(months > 0) {
			D = (float) (priceTag * firstPercent / 100); //prio-pay
			C = priceTag - D;
			B = C / months;
			double tmp = eachMonthPercent / 100;
			
			for (int i = 0; i <= months; i++) {
				switch (type) {
				case 1:
					Z += (C - i * B) * tmp;
					break;
				case 2:
					Z += (C - i * B + Z) * tmp;
					break;
				default:
					break;
				}
			}
			
			B = (C + Z) / months;
		} else {
			B = 0;
			D = priceTag;
		}
		
		float total = (float) Math.ceil(Z + priceTag);

		String[] outPut = new String[10];

		outPut[0] = String.valueOf(priceTag);
		outPut[1] = String.valueOf(firstPercent);
		outPut[2] = String.valueOf(eachMonthPercent);
		outPut[3] = String.valueOf(months);
		outPut[4] = String.valueOf(type);
		outPut[5] = String.valueOf(D);
		outPut[6] = String.valueOf(C);
		outPut[7] = String.valueOf(B);
		outPut[8] = String.valueOf(Z);
		outPut[9] = String.valueOf(total);

		return outPut;
	}
}
